﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SqlCeViewer.Base;
using SqlCeViewer.CommonMethod;
using System.IO;

namespace SqlCeViewer.UI
{
    public partial class Excel2Sdf : BaseSubForm
    {
        public Excel2Sdf()
        {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(buttonEdit1.Text))
            {
                MessageBox.Show("Please select source access file first");
                return;
            }
            if (!File.Exists(buttonEdit1.Text))
            {
                MessageBox.Show("File not existed,please try again");
                return;
            }
            string sdfFile = string.Empty;

            SaveFileDialog sf = new SaveFileDialog();
            sf.Filter = GlobalInfo.SQLCE_FILE_FILTER;
            if (sf.ShowDialog() == DialogResult.OK)
            {
                sdfFile = sf.FileName;
                string excelFile = this.buttonEdit1.Text;
                if (!string.IsNullOrEmpty(excelFile))
                {
                    if (CommonUtil.ConvertEXCELToSdf(excelFile, sdfFile, (bool)this.checkEdit1.Checked))
                    {
                        MessageBox.Show(String.Format("Sync data from \r\n{0} \r\nto \r\n{1} \r\nSuccessful.", excelFile, sdfFile));
                        Close();
                    }
                }
            }
        }

        private void buttonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            OpenFileDialog sf = new OpenFileDialog();
            sf.Filter = GlobalInfo.MDB_FILE_FILTER;
            if (sf.ShowDialog() == DialogResult.OK)
            {
                this.buttonEdit1.Text = sf.FileName;
            }
        }
    }
}